package com.fairisanddog.hadooptest.worddriver;


import com.fairisanddog.hadooptest.wordmapper.WordMappercart;
import com.fairisanddog.hadooptest.wordreducer.WordReducercart;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class WordDrivercart {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

        Configuration conf = new Configuration();
        conf.setClassLoader(WordDrivercart.class.getClassLoader());
        Job job = Job.getInstance(conf);
        job.setJarByClass(WordDrivercart.class);
        job.setMapperClass(WordMappercart.class);
        job.setReducerClass(WordReducercart.class);
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);

        FileInputFormat.setInputPaths(job,new Path("C:/Users/李东阳/Desktop/hadoop分析/分析文件/cart.txt"));
        FileOutputFormat.setOutputPath(job,new Path("C:/Users/李东阳/Desktop/hadoop分析/分析结果/cart"));

        Boolean completion = job.waitForCompletion(true);
        if (completion){
            System.out.println("ok");
        }else {
            System.out.println("no");
        }

    }
}
